<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>AutoIt修改Assembly的版本号 | Wentao&#39;s Blog</title>

  
  <meta name="author" content="wentao">
  

  
  <meta name="description" content="部门搞了自动构建.以前自己也用过ccnet之类的工具.有很多的版本号递增的规则很是方便.可惜我们不是用类似的工具,所以版本号这块就只能自己手动来修改了.不过这个修改也挺麻烦的.后来就考虑写一个小工具来完成版本号的修改.本来打算用C#做一个.但是还依赖.Net Framework.刚好最近看了一下Au">
  

  
  
  <meta name="keywords" content=".Net,AutoIt">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="AutoIt修改Assembly的版本号"/>

  <meta property="og:site_name" content="Wentao&#39;s Blog"/>

  
  <meta property="og:image" content="/favicon.ico"/>
  

  <link href="/favicon.ico" rel="icon">
  <link rel="alternate" href="/atom.xml" title="Wentao&#39;s Blog" type="application/atom+xml">
  <link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">
</head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/">Wentao&#39;s Blog</a>
    </h1>
    <p class="site-description"></p>
  </div>
  <nav class="site-navigation">
    <ul>
      
        <li><a href="/">主页</a></li>
      
        <li><a href="/archives">归档</a></li>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>AutoIt修改Assembly的版本号</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/2013/04/18/2013-4-18-Change-Assembly-Version/" rel="bookmark">
        <time class="entry-date published" datetime="2013-04-18T08:26:25.000Z">
          2013-04-18
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <p>部门搞了自动构建.以前自己也用过<code>ccnet</code>之类的工具.有很多的版本号递增的规则很是方便.可惜我们不是用类似的工具,所以版本号这块就只能自己手动来修改了.不过这个修改也挺麻烦的.后来就考虑写一个小工具来完成版本号的修改.本来打算用<code>C#</code>做一个.但是还依赖<code>.Net Framework</code>.刚好最近看了一下<code>AutoIt</code>,就用这个练习了一下.于是就做出了这么一个东东.</p>
<p><figure class="highlight autoit"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">NoTrayIcon</span></span></div><div class="line"><span class="meta">#region <span class="comment">;**** Directives created by AutoIt3Wrapper_GUI ****</span></span></div><div class="line"><span class="meta">#AutoIt3Wrapper_Icon=ti.ico</span></div><div class="line"><span class="meta">#AutoIt3Wrapper_Run_Tidy=y</span></div><div class="line"><span class="meta">#endregion <span class="comment">;**** Directives created by AutoIt3Wrapper_GUI ****</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;File.au3&gt;</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;Array.au3&gt;</span></span></div><div class="line"></div><div class="line"><span class="keyword">Local</span> $path = <span class="string">'D:\code\batchAgent'</span></div><div class="line"><span class="keyword">Local</span> $aVersion = <span class="string">'1.0.0.3'</span></div><div class="line"><span class="keyword">Local</span> $aRecords</div><div class="line"><span class="keyword">If</span> $CmdLine[0] &gt;= <span class="number">2</span> <span class="keyword">Then</span></div><div class="line">	$path = $CmdLine[1]</div><div class="line">	$aVersion = $CmdLine[2]</div><div class="line"><span class="keyword">Else</span></div><div class="line">	<span class="built_in">MsgBox</span>(<span class="number">0</span>, <span class="string">"Warn"</span>, <span class="string">'测试模式'</span>)</div><div class="line"><span class="keyword">EndIf</span></div><div class="line"><span class="keyword">Local</span> $var = <span class="built_in">StringRight</span>($path, <span class="number">1</span>)</div><div class="line"></div><div class="line"><span class="keyword">If</span> <span class="built_in">StringCompare</span>($var, <span class="string">'\'</span>) &lt;&gt; <span class="number">0</span> <span class="keyword">Then</span></div><div class="line">	$path = $path &amp; <span class="string">'\'</span></div><div class="line"><span class="keyword">EndIf</span></div><div class="line"></div><div class="line"><span class="keyword">Local</span> $FileList = _FileListToArray($path, <span class="string">'*'</span>, <span class="number">2</span>)</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">For</span> $i = <span class="number">1</span> <span class="keyword">To</span> $FileList[0]</div><div class="line"></div><div class="line">	<span class="keyword">If</span> _FileReadToArray($path &amp; $FileList[$i] &amp; <span class="string">'\Properties\AssemblyInfo.cs'</span>, $aRecords) <span class="keyword">Then</span></div><div class="line">		<span class="comment">;_ArrayDisplay($aRecords, "$aRecords")</span></div><div class="line">		<span class="keyword">For</span> $y = <span class="number">1</span> <span class="keyword">To</span> $aRecords[0]</div><div class="line">			<span class="keyword">Local</span> $result = <span class="built_in">StringRegExp</span>($aRecords[$y], <span class="string">"^\[assembly\:\s\w*Version"</span>)</div><div class="line"></div><div class="line">			<span class="keyword">If</span> $result &gt; <span class="number">0</span> <span class="keyword">Then</span></div><div class="line">				<span class="comment">;用正则替换</span></div><div class="line">				<span class="keyword">Local</span> $sOutput = <span class="built_in">StringRegExpReplace</span>($aRecords[$y], <span class="string">'\"([\d&#123;1,&#125;?\.]*)\"'</span>, <span class="string">'"'</span> &amp; $aVersion &amp; <span class="string">'"'</span>)</div><div class="line">				$aRecords[$y] = $sOutput</div><div class="line"></div><div class="line">			<span class="keyword">EndIf</span></div><div class="line">		<span class="keyword">Next</span></div><div class="line">		<span class="keyword">Local</span> $hFile = <span class="built_in">FileOpen</span>($path &amp; $FileList[$i] &amp; <span class="string">'\Properties\AssemblyInfo.cs'</span>, <span class="number">2</span> + <span class="number">128</span>) <span class="comment">; 1 = append</span></div><div class="line">		<span class="keyword">For</span> $y = <span class="number">1</span> <span class="keyword">To</span> $aRecords[0]</div><div class="line">			<span class="keyword">Local</span> $hFileWrite = <span class="built_in">FileWrite</span>($hFile, $aRecords[$y] &amp; <span class="symbol">@CRLF</span>)</div><div class="line">		<span class="keyword">Next</span></div><div class="line">		<span class="built_in">FileClose</span>($hFile)</div><div class="line">	<span class="keyword">EndIf</span></div><div class="line"><span class="keyword">Next</span></div></pre></td></tr></table></figure></p>
<p>用上面的脚本编译一个exe,然后传递一个项目的路径和版本号就可以把Assembly的版本号改掉了.</p>

      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/categories/Dev/">Dev</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/tags/Net-AutoIt/">.Net,AutoIt</a>
    </span>
    

    </div>

    
  </div>
</article>

  
	<div id="comment">
	
	
	<!-- 多说评论框 start -->
	 <div class="ds-thread" data-thread-key="/2013/04/18/2013-4-18-Change-Assembly-Version/" data-title="AutoIt修改Assembly的版本号" data-url="http://wentao.org/2013/04/18/2013-4-18-Change-Assembly-Version/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"wentao"};
	  (function() {
	    var ds = document.createElement('script');
	    ds.type = 'text/javascript';ds.async = true;
	    ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
	    ds.charset = 'UTF-8';
	    (document.getElementsByTagName('head')[0] 
	     || document.getElementsByTagName('body')[0]).appendChild(ds);
	  })();
	  </script>
	<!-- 多说公共JS代码 end -->
	
	</div>




    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2016 wentao
    
  </p>
</footer>
    
  </div>
</div>
</body>
</html>